#!/bin/sh
#
# Build Applications from scratch (with GPL v2).
#
# Authors: 
#	Conke   <conke.hu@gmail.com>
# 	Linke   <linke.wang@gmail.com>
#


PREGEN_PATH=${MWL_TOP}/linux/rootfs/pregen

if [ -d ${ROOTFS_PATH} ]; then
	echo "Removing old rootfs dir: ${ROOTFS_PATH}"
	rm -rf ${ROOTFS_PATH}
fi

mkdir -vp ${ROOTFS_PATH}


echo -n "Populating system dir: "
for dir in lib bin sbin usr/lib usr/share; do
	mkdir -p ${ROOTFS_PATH}/${dir}
	echo -n "$dir "
done

echo "done."


cd ${SYSROOT_PATH}
cp -a lib/*.so* ${ROOTFS_PATH}/lib/
cp -a usr/lib/*.so* ${ROOTFS_PATH}/usr/lib/

DFB_LIB=`find usr/lib/directfb* -name "*directfb*.so*"` > /dev/null 2>&1
if [ x"${DFB_LIB}" != x"" ]; then
	cp -a --parents  $DFB_LIB ${ROOTFS_PATH}
fi


cp -a ${SYSROOT_PATH}/usr/bin ${ROOTFS_PATH}/usr/ && \
cp -a ${SYSROOT_PATH}/sbin ${ROOTFS_PATH}/ && \
cp -a ${SYSROOT_PATH}/usr/sbin ${ROOTFS_PATH}/usr/ && \
cp -a ${SYSROOT_PATH}/bin ${ROOTFS_PATH}/ && \
cp -a ${SYSROOT_PATH}/usr/share/terminfo ${ROOTFS_PATH}/usr/share && \
cp -a ${SYSROOT_PATH}/usr/share/alsa ${ROOTFS_PATH}/usr/share && \
cp ${SYSROOT_PATH}/usr/share/usb.ids ${ROOTFS_PATH}/usr/share || exit

${MWL_TOP}/linux/rootfs/com-rfs.sh ${ROOTFS_PATH} || exit

if [ -x ${MWL_TOP}/linux/rootfs/mkrootfsimg.sh ]; then
	${MWL_TOP}/linux/rootfs/mkrootfsimg.sh || exit 1
fi

echo "rootfs (${ROOTFS_PATH}) have been built successfully!"
echo "If any question, please contact:"
echo "  Conke   <conke.hu@gmail.com>"
echo "  Linke   <linke.wang@gmail.com>"
echo


